/*
 * $Id: ProfileDTCommandBuilder.java 42 2013-04-17 15:33:59Z gabakyan $
 * $Author: gabakyan $
 * $Revision: 42 $
 * $Date: 2013-04-17 15:33:59 +0000 (Wed, 17 Apr 2013) $
 *
 * Copyright (c) 2013 Supply Chain Intelligence (SCI), Inc.
 * http://www.scintelligence.com/, Email: info@scintelligence.com
 * All rights reserved.
 *
 * This file is part of Logistics Map.
 *
 * Logistics Map is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * Logistics Map is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Logistics Map.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.sci.logisticsmap.service.support.builder;

import com.sci.logisticsmap.data.model.UserModel;
import com.sci.logisticsmap.service.model.ProfileDTCommand;
import com.sci.logisticsmap.support.builder.BaseBuilder;

/**
 * The class {@code ProfileDTCommandBuilder} represents the {@link ProfileDTCommand} builder.
 *
 * @author gabakyan@gmail.com (Last modified by $Author: gabakyan $)
 * @version $Revision: 42 $
 */
public class ProfileDTCommandBuilder extends BaseBuilder<ProfileDTCommand> {
    /**
     * The user.
     */
    private UserModel user;

    /**
     * The default constructor.
     */
    public ProfileDTCommandBuilder() {
    }

    /*
     * (non-Javadoc)
     *
     * @see com.sci.logisticsmap.support.builder.BaseBuilder#build()
     */
    public ProfileDTCommand build() {
        ProfileDTCommand command = new ProfileDTCommand();
        if (user != null) {
            fillProfileCommand(command, user);
            user = null;
        }
        return command;
    }

    /**
     * Sets the user.
     *
     * @param user The user.
     *
     * @return The reference to the {@link ProfileDTCommand} builder.
     */
    public ProfileDTCommandBuilder setUser(UserModel user) {
        this.user = user;
        return this;
    }

    /**
     * Fills the profile command.
     *
     * @param command The target profile command.
     * @param user The source user model.
     */
    private void fillProfileCommand(ProfileDTCommand command, UserModel user) {
        command.setUsername(user.getUsername());
        command.setPassword(user.getPassword());
        command.setFirstName(user.getFirstName());
        command.setLastName(user.getLastName());
    }
}
